<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\admin\middleware\Auth;
use app\model\BannersModel;
use app\model\InnerTestConfigModel;
use app\model\InnerTestUserModel;
use app\model\RedisModel;
use think\App;
use think\facade\Db;

class InnerTestConfig extends Base {

    protected $middleware = [Auth::class];
    private $innerTestConfigModel;

    public $cacheKey="inner:test:config";

    private $req;


    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->innerTestConfigModel = new InnerTestConfigModel();

        $this->innerTestUserModel = new InnerTestUserModel();

        $this->req =  request()->param();

        $this->isLogin();
    }



    public function getInfo()
    {
        return $this->succ($this->innerTestConfigModel->getInfo());
    }





    /*
     * 关闭
     * */
    public function updateStatus(){
        $res = $this->innerTestConfigModel->where(["id"=>1])->save([
            "is_all_open"=>$this->req['is_all_open'],
            "auditValue"=>$this->req['auditValue']
        ]);

        if($res){
            $this->delAllCache();
            return $this->succ();
        }else{
            return $this->fail();
        }

    }



    public function delCache($id)
    {
        $redisModel = new RedisModel();

        return $redisModel->delete($this->cacheKey.$id);
    }


    public function delAllCache()
    {
        $redisModel = new RedisModel();

        return $redisModel->deleteAll($this->cacheKey);
    }

}
